package com.example.a22310.myapplication.Model;

import com.example.a22310.myapplication.Beans.Attention;
import com.example.a22310.myapplication.Beans.user;
import com.example.a22310.myapplication.Listener.ActivityLisenter;
import com.example.a22310.myapplication.Service.service;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static android.provider.ContactsContract.CommonDataKinds.Website.URL;

public class AttentionModel {




    private Retrofit retrofit;
    public AttentionModel()
    {

        retrofit= new Retrofit.Builder()
                .baseUrl(URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void attentionlist(final ActivityLisenter<Attention> lisenter, int userid, int flag) {
        service service = retrofit.create(service.class);
        Call<Attention> call = service.attentionlist(userid,flag);
        Callback<Attention> callback = new Callback<Attention>() {
            @Override
            public void onResponse(Call<Attention> call, Response<Attention> response) {
                Attention activitys = response.body();
                lisenter.onSuccess(activitys);
            }
            @Override

            public void onFailure(Call<Attention> call, Throwable t) {
                lisenter.onFailure();
            }
        };
        call.enqueue(callback);
    }


    public void addAttention(final ActivityLisenter<user> lisenter, int userid, int attentionid, String name,
                             String pic, int flag) {//添加关注
       service service = retrofit.create(service.class);
        Call<user> call = service.addAttention(userid,attentionid,name,pic,flag);
        Callback<user> callback = new Callback<user>() {
            @Override
            public void onResponse(Call<user> call, Response<user> response) {
                user user = response.body();
                lisenter.onSuccess(user);
            }
            @Override

            public void onFailure(Call<user> call, Throwable t) {
                lisenter.onFailure();
            }
        };
        call.enqueue(callback);
    }


}

